() * () (block)
The () * () block is an Operators block and a Reporter block. The block multiplies the two values and reports the result. The numbers can be typed directly into the block, or Reporter blocks can be used instead. This block can be stacked inside itself - this can be used to fit more numbers in or calculate exponents. Example Uses In many projects, numbers must be multiplied; this block will do the job. Some common uses for the () * () block: *Scripts in calculator simulations set v to ((a) * (b)) *Multiplying lists of numbers set v to (1) set v to (1) repeat (length of v) set v to ((result) * (item (item) of v)) change v by (1) end *Math formulas (v of ((((y1) - (y2)) * ((y1) - (y2))) + (((x1) - (x2)) * ((x1) - (x2))))) //Pythagorean Theorem *Score multipliers set v to ((score) * (2)) *Velocity when gf clicked set v to 0 forever if change v by (2) set v to ((velocity) * (0.87)) //simulates friction slowdown *3D Projects Scientific Notation In Scratch 1.4 and previous versions, it sometimes converts very large numbers into scientific notation to save space. Scientific notation is simply the number in the form a*10b. These can be converted to a normal number by performing any mathematical function on it, such as adding. So if a variable named "number" has a value of 3*103 and you want to display it as a normal number, you can change it by: ((number) + (0)) It will then report "3000". Workaround With natural numbers, this block can be replicated with the following code, assuming a is the first number and b is the second number: set v to 0 repeat (b) change v by (a) The following code works for all cases (with the conditional). It divides by the reciprocal, the equivalent of multiplying. if <(b) = (0)> then set v to 0 else set v to ((a) / ((1) / (b))) end The following code accepts negative numbers with decimals: delete (all v) of numbers v //setup delete (all v) of numbers v delete (all v) of digits v set v to 0 set pos 1 v to 0 set pos 2 v to 0 ask num1 and wait if <(answer) < 0> then set v to 1 set 1 negative v to y else set v to 0 set 1 negative v to n end repeat (length of (answer)) change v by (1) if <(letter (count) of (answer)) = .>> then add (letter (count) of (answer)) to numbers v else set pos 1 v to ((length of (answer)) - (count)) end end ask num2 and wait if <(answer) < 0> then set v to 1 set 2 negative v to y else set v to 0 set 2 negative v to n end repeat (length of (answer)) change v by (1) if <(letter (count) of (answer)) = .>> then add (letter (count) of (answer)) to numbers v else set pos 2 v to ((length of (answer)) - (count)) end end set v to (num1 numbers) set v to (num2 numbers) repeat (num1) //start change v by (num2) end set position v to ((dec pos 1) + (dec pos 2)) set v to 0 repeat (length of (product)) change v by (1) add (letter (count) of (product)) to digits v end if <(decimal position) = 0>> then insert . at ((length of digits v) - ((decimal position) - (1))) of digits v end if <<<(no 1 negative) = y> or <(no 2 negative) = y>> and <<(no 1 negative) = y> and <(no 2 negative) = y>>>> then insert - at (1 v) of digits v end set v to (product digits) See Also *() + () *() - () *() / () de:()*() (Block) id:()_*_()_(balok) Category:Operators Blocks